#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int N = 4e5 + 10;
int n, tot, ans, sum, cnt, vis[N];
int a[N], b[N];
vector<int> g[N];
 
void dfs(int x){
	if(vis[x]){
		return;
	}
	vis[x] = 1;
	++ cnt;
	sum += g[x].size();
	for(int i : g[x]){
		dfs(i);
	}
}
 
int main(){
	freopen("pairint.in", "r", stdin);
	freopen("pairint.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i){
		scanf("%d%d", &a[i], &b[i]);
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	for(int i = 1; i <= n + n; ++ i){
		sum = cnt = 0;
		if(!vis[i]){
			dfs(i);
			if(sum / 2 == cnt - 1){
				++ ans;
			}
		}
	}
	printf("%d\n", n + n - ans);
	return 0;
}